import request from './request.js'
//封装请求的api
const callApi = (url,method,data) => {
    // return request({
    //     url: url,
    //     method: method,
    //     params: method === "GET" ? data : {},
    //     data: method === "POST" ? data : {},
    // });
    const config = { url: url, method: method };
    if(method === 'GET' || method === "DELETE") {
        config.params = data;
    } else if(method === 'POST' || method === "PUT") {
        config.data = data;
    }
    return request(config);
};
export const getApi = (url,data) => callApi(url,'GET',data)
export const postApi = (url,data) => callApi(url,'POST',data)
export const deleteApi = (url,data) => callApi(url,'DELETE',data)
export const putApi = (url,data) => callApi(url,'PUT',data)

/** 管理员界面接口 */
export const adminApi = {
    getDonators: data => getApi('/donator/getDonators', data), // 获取捐赠者列表
    deleteDonators: data => postApi('/donator/deleteDonator', data), // 删除捐赠者
    addDonator: data => postApi('/donator/addDonator', data), // 添加捐赠者
    updateDonator: data => putApi('/donator/updateDonator', data), // 更新捐赠者信息
    getDonationRecordsByDonatorId: data => getApi('/donationRecords/getDonationRecordsByDonatorId', data), // 根据捐赠者id获取捐赠记录列表
    getDonationRecords: data => getApi('/donationRecords/getDonationRecords', data), // 获取捐赠记录列表
    getFundraisingProjects: data => getApi('/fundraisingProjects/getDonationRecords', data), // 获取募捐项目列表
    getAgencyIdAndName: data => getApi('/agency/getAgencyIdAndName', data), // 获取机构id和名称
    updateFundraisingProject: data => putApi('/fundraisingProjects/updateFundraisingProject', data), // 更新募捐项目信息
    addFundraisingProject: data => postApi('/fundraisingProjects/addFundraisingProject', data), // 添加募捐项目
    deleteFundraisingProjects: data => postApi('/fundraisingProjects/deleteFundraisingProjects', data), // 删除募捐项目
    getUnreviewedFundraisingProjects: data => getApi('/fundraisingProjects/getUnreviewedFundraisingProjects', data), // 获取未审核的募捐项目列表
    getAgencies: data => getApi('/agency/getAgencies', data), // 获取募捐机构列表
    addAgency: data => postApi('/agency/addAgency', data), // 添加募捐机构
    updateAgency: data => putApi('/agency/updateAgency', data), // 更新募捐机构信息
    deleteAgencies: data => postApi('/agency/deleteAgencies', data), // 删除募捐机构
    getComments: data => getApi('/comment/getAllComments', data), // 获取评论列表
    deleteComments: data => postApi('/comment/deleteComments', data), // 删除评论
}

/** 募捐机构界面接口 */
export const agencyApi = {
    toLogin: data => getApi('/agency/getAgencyByIdAndPassword', data), // 登录
    getFundraisingProjects: data => getApi('/fundraisingProjects/getFundraisingProjectsByAgencyId', data), // 获取募捐项目列表
    getFundraisingProjectsAndMoney: data => getApi('/fundraisingProjects/getFundraisingProjectsMoney', data), // 获取募捐项目列表和金额
    getDonationProcessingRecords: data => getApi('/donationProcessing/getDonationProcessingByFundraisingProjectsId', data), // 获取捐赠处理记录列表
    getDonationRecords: data => getApi('/donationRecords/getDonationRecordsByProjectId', data), // 获取捐赠记录列表
    addDonationProcessing: data => postApi('/donationProcessing/addDonationProcessing', data), // 添加捐款处理记录
}

/** 捐赠者界面接口 */
export const donatorApi = {
    toLogin: data => getApi('/donator/login', data), // 登录
    uploadAvatar: data => postApi('/file/upload', data), // 上传头像
    getFourFundraisingProjects: data => getApi('/fundraisingProjects/getFourFundraisingProjects', data), // 获取推荐的四个募捐项目列表
    getFundraisingProjectsById: data => getApi('/fundraisingProjects/getFundraisingProjectById', data), // 根据id获取募捐项目信息
    toDonate: data => postApi('/donationRecords/addDonationRecord', data), // 捐赠
    sendCode: data => getApi('/donator/sendCode', data), // 发送验证码
    toRegister: data => getApi('/donator/register', data), // 注册
    toChangePassword: data => getApi('/donator/updateDonatorPassword', data), // 修改密码
    getFundraisingProjectsByType: data => getApi('/fundraisingProjects/getFundraisingProjectsByType', data), // 根据类型获取募捐项目列表
    getCommentByFundraisingProjectsId: data => getApi('/comment/getCommentByFundraisingProjectsId', data), // 根据项目id获取评论列表
    addComment: data => postApi('/comment/addComment', data), // 添加评论
}